<template>
	<view class="container">
		<!-- 评价统计 -->
		<view class="review-stats">
			<view class="overall">
				<view class="score">{{productInfo.rating}}</view>
				<view class="total">共{{productInfo.reviewCount}}条评价</view>
			</view>
			<view class="tags">
				<view 
					class="tag-item" 
					v-for="(item, index) in reviewTags" 
					:key="index"
					:class="{'active': currentTag === item.value}"
					@click="switchTag(item.value)"
				>
					<text>{{item.label}}</text>
					<text class="count">({{item.count}})</text>
				</view>
			</view>
		</view>
		
		<!-- 评价列表 -->
		<scroll-view 
			scroll-y 
			class="review-list"
			@scrolltolower="loadMore"
			refresher-enabled
			:refresher-triggered="isRefreshing"
			@refresherrefresh="onRefresh"
		>
			<view 
				class="review-item" 
				v-for="(item, index) in reviewList" 
				:key="index"
			>
				<view class="user-info">
					<image :src="item.userAvatar" mode="aspectFill" class="avatar"></image>
					<view class="info">
						<text class="nickname">{{item.userName}}</text>
						<view class="rating">
							<text class="score">{{item.rating}}</text>
							<text class="time">{{item.createTime}}</text>
						</view>
					</view>
				</view>
				<view class="content">{{item.content}}</view>
				<view class="images" v-if="item.images && item.images.length > 0">
					<image 
						v-for="(img, imgIndex) in item.images" 
						:key="imgIndex"
						:src="img"
						mode="aspectFill"
						class="review-img"
						@click="previewImage(item.images, imgIndex)"
					></image>
				</view>
				<view class="product-info" v-if="item.productInfo">
					<image :src="item.productInfo.image" mode="aspectFill" class="product-img"></image>
					<view class="product-detail">
						<text class="name">{{item.productInfo.name}}</text>
						<text class="spec">{{item.productInfo.spec}}</text>
					</view>
				</view>
			</view>
			
			<!-- 加载更多 -->
			<view class="loading-more" v-if="hasMore">
				<text>加载中...</text>
			</view>
			<view class="no-more" v-else>
				<text>没有更多了</text>
			</view>
			
			<!-- 空状态 -->
			<view class="empty-state" v-if="reviewList.length === 0">
				<image src="/static/images/empty.png" mode="aspectFit" class="empty-img"></image>
				<text class="empty-text">暂无评价</text>
			</view>
		</scroll-view>
	</view>
</template>

<script setup>
import { ref } from 'vue'

// 商品信息
const productInfo = ref({
	id: '10001',
	name: '川味火锅底料',
	rating: '4.8',
	reviewCount: 128
})

// 评价标签
const reviewTags = ref([
	{ label: '全部', value: 'all', count: 128 },
	{ label: '好评', value: 'good', count: 98 },
	{ label: '中评', value: 'medium', count: 20 },
	{ label: '差评', value: 'bad', count: 10 }
])

// 当前选中的标签
const currentTag = ref('all')

// 是否还有更多数据
const hasMore = ref(true)

// 是否正在刷新
const isRefreshing = ref(false)

// 评价列表
const reviewList = ref([
	{
		id: '1',
		userName: '火锅达人',
		userAvatar: 'https://img.alicdn.com/imgextra/i4/O1CN01XCiY1B1nx2Xh2Z9tP_!!6000000005155-0-tps-1316-736.jpg',
		rating: '5.0',
		content: '味道很好，很正宗，包装也很精美，物流速度快，好评！',
		createTime: '2024-03-15',
		images: [
			'https://img.alicdn.com/imgextra/i4/O1CN01XCiY1B1nx2Xh2Z9tP_!!6000000005155-0-tps-1316-736.jpg',
			'https://img.alicdn.com/imgextra/i2/O1CN01F0MA5j1zXb0XcYV1F_!!6000000006733-0-tps-1316-736.jpg'
		],
		productInfo: {
			name: '川味火锅底料',
			spec: '500g/袋',
			image: 'https://img.alicdn.com/imgextra/i4/O1CN01XCiY1B1nx2Xh2Z9tP_!!6000000005155-0-tps-1316-736.jpg'
		}
	},
	{
		id: '2',
		userName: '美食家',
		userAvatar: 'https://img.alicdn.com/imgextra/i2/O1CN01F0MA5j1zXb0XcYV1F_!!6000000006733-0-tps-1316-736.jpg',
		rating: '4.0',
		content: '味道不错，就是有点咸，建议少放一点。',
		createTime: '2024-03-14',
		images: [],
		productInfo: {
			name: '川味火锅底料',
			spec: '500g/袋',
			image: 'https://img.alicdn.com/imgextra/i4/O1CN01XCiY1B1nx2Xh2Z9tP_!!6000000005155-0-tps-1316-736.jpg'
		}
	}
])

// 切换标签
const switchTag = (tag) => {
	currentTag.value = tag
	// 重置列表并重新加载
	reviewList.value = []
	hasMore.value = true
	loadMore()
}

// 加载更多
const loadMore = () => {
	if (!hasMore.value) return
	
	// 这里可以添加加载更多评价的接口调用
	setTimeout(() => {
		hasMore.value = false
	}, 1000)
}

// 下拉刷新
const onRefresh = () => {
	isRefreshing.value = true
	// 重置列表并重新加载
	reviewList.value = []
	hasMore.value = true
	
	setTimeout(() => {
		isRefreshing.value = false
		loadMore()
	}, 1000)
}

// 预览图片
const previewImage = (images, current) => {
	uni.previewImage({
		urls: images,
		current: images[current]
	})
}
</script>

<style>
.container {
	min-height: 100vh;
	background-color: #F5F5F5;
}

/* 评价统计样式 */
.review-stats {
	background-color: #FFFFFF;
	padding: 30rpx;
	margin-bottom: 20rpx;
}

.overall {
	display: flex;
	align-items: center;
	margin-bottom: 30rpx;
}

.score {
	font-size: 48rpx;
	font-weight: bold;
	color: #D02B29;
	margin-right: 30rpx;
}

.total {
	font-size: 28rpx;
	color: #666;
}

.tags {
	display: flex;
	flex-wrap: wrap;
}

.tag-item {
	padding: 10rpx 30rpx;
	background-color: #F5F5F5;
	border-radius: 30rpx;
	margin-right: 20rpx;
	margin-bottom: 20rpx;
	font-size: 24rpx;
	color: #666;
}

.tag-item.active {
	background-color: #FFF0F0;
	color: #D02B29;
}

.tag-item .count {
	margin-left: 10rpx;
}

/* 评价列表样式 */
.review-list {
	height: calc(100vh - 200rpx);
}

.review-item {
	background-color: #FFFFFF;
	padding: 30rpx;
	margin-bottom: 20rpx;
}

.user-info {
	display: flex;
	align-items: center;
	margin-bottom: 20rpx;
}

.avatar {
	width: 80rpx;
	height: 80rpx;
	border-radius: 50%;
	margin-right: 20rpx;
}

.info {
	flex: 1;
}

.nickname {
	font-size: 28rpx;
	color: #333;
	margin-bottom: 10rpx;
	display: block;
}

.rating {
	display: flex;
	align-items: center;
}

.score {
	font-size: 24rpx;
	color: #FFB800;
	margin-right: 20rpx;
}

.time {
	font-size: 24rpx;
	color: #999;
}

.content {
	font-size: 28rpx;
	color: #333;
	line-height: 1.6;
	margin-bottom: 20rpx;
}

.images {
	display: flex;
	flex-wrap: wrap;
	margin-bottom: 20rpx;
}

.review-img {
	width: 200rpx;
	height: 200rpx;
	margin-right: 20rpx;
	margin-bottom: 20rpx;
	border-radius: 10rpx;
}

.product-info {
	display: flex;
	background-color: #F5F5F5;
	padding: 20rpx;
	border-radius: 10rpx;
}

.product-img {
	width: 120rpx;
	height: 120rpx;
	border-radius: 10rpx;
	margin-right: 20rpx;
}

.product-detail {
	flex: 1;
}

.name {
	font-size: 24rpx;
	color: #333;
	margin-bottom: 10rpx;
	display: block;
}

.spec {
	font-size: 24rpx;
	color: #999;
}

/* 加载更多样式 */
.loading-more, .no-more {
	text-align: center;
	padding: 20rpx 0;
	font-size: 24rpx;
	color: #999;
}

/* 空状态样式 */
.empty-state {
	padding: 100rpx 0;
	text-align: center;
}

.empty-img {
	width: 200rpx;
	height: 200rpx;
	margin-bottom: 20rpx;
}

.empty-text {
	font-size: 28rpx;
	color: #999;
}
</style> 